def finde_jiaoji(arr1, arr2):
    arr1_temp = sorted(arr1)
    arr2_temp = sorted(arr2)

    ret = []
    i = j = 0
    while i < len(arr1_temp) and j < len(arr2_temp):
        if arr1_temp[i] < arr2_temp[j]:
            i = i + 1
        elif arr1_temp[i] > arr2_temp[j]:
            j = j + 1
        else:
            ret.append(arr1_temp[i])
            i = i + 1
            j = j + 1
    return ret

nums1 = [1,2,2,1]
nums2 = [2,2]
print(finde_jiaoji(nums1, nums2))

nums3 = [4,9,5]
nums4 = [9,4,9,8,4]
print(finde_jiaoji(nums3, nums4))

nums5 = [1,1,2]
nums6 = [1,1,1]
print(finde_jiaoji(nums5, nums6))
